﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using TSSControlLibrary;
using TaskSchedulingSystemClassLibrary.DataModel;
namespace TaskSchedulingSystemClassLibrary.IO
{
    /// <summary>
    /// 任务调度系统专属输入输出
    /// </summary>
    public static class DIYConsole
    {
        static List<TaskModel> taskCarryNowLst;
        static IOControlModel ioControl;
        ///// <summary>
        ///// 静态构造函数
        ///// </summary>
        ///// <param name="u"></param>
        ///// <param name="ATaskIdAndStatePool"></param>
        ///// <param name="AtaskCarryNowLst"></param>
        //static DIYConsole(DisPlayIOInfoUserControl u, Dictionary<int, bool> ATaskIdAndStatePool, List<TaskModel> AtaskCarryNowLst)
        //{
        //    userControl = u;
        //    TaskIdAndStatePool = ATaskIdAndStatePool;
        //    taskCarryNowLst = AtaskCarryNowLst;
        //}
        /// <summary>
        /// 初始化自定义输入输出
        /// </summary>
        /// <param name="u"></param>
        /// <param name="TaskIdAndStatePool"></param>
        public static void InitializeConsole( List<TaskModel> AtaskCarryNowLst,IOControlModel ioc)
        {    
            taskCarryNowLst = AtaskCarryNowLst;
            ioControl = ioc;
        }
        /// <summary>
        /// 输出一行
        /// </summary>
        public static void WriteLine(string value, int taskId)
        {
            while (true)
            {
                if (ioControl.isEnd)
                {
                    ioControl.carryingTaskId = taskId;
                    ioControl.value = value;                  
                    ioControl.isEnd = false;
                    break;
                }
                else
                {
                    Thread.Sleep(1000);
                }
            }
        }
        public static void WriteLine(string format, object arg0, int taskId)
        {
            while (true)
            {
                if (ioControl.isEnd)
                {                   
                    ioControl.carryingTaskId = taskId;
                    ioControl.value = string.Format(format, arg0);
                    ioControl.isEnd = false;
                    break;
                }
                else
                {
                    Thread.Sleep(1000);
                }
            }
        }
        public static void WriteLine(string format, object arg0, object arg1, int taskId)
        {
            while (true)
            {
                if (ioControl.isEnd)
                {
                    ioControl.carryingTaskId = taskId;
                    ioControl.value = string.Format(format, arg0, arg1);
                    ioControl.isEnd = false;
                    break;
                }
                else
                {
                    Thread.Sleep(1000);
                }
            }
        }
        public static void WriteLine(string format, object arg0, object arg1, object arg2, int taskId)
        {
            while (true)
            {
                if (ioControl.isEnd)
                {
                    ioControl.carryingTaskId = taskId;
                    ioControl.value = string.Format(format, arg0, arg1,arg2);
                    ioControl.isEnd = false;
                    break;
                }
                else
                {
                    Thread.Sleep(1000);
                }
            }
        }
        public static void WriteLine(string format, object arg0, object arg1, object arg2, object arg3, int taskId)
        {
            while (true)
            {
                if (ioControl.isEnd)
                {
                    ioControl.carryingTaskId = taskId;
                    ioControl.value = string.Format(format, arg0, arg1,arg2,arg3);
                    ioControl.isEnd = false;
                    break;
                }
                else
                {
                    Thread.Sleep(1000);
                }
            }
        }
        /// <summary>
        /// 读入一行
        /// </summary>
        public static string ReadLine()
        {
            return Console.ReadLine();
        }
    }
}
